/*
 * Copyright (C), CVTE Electronics CO.Ltd 2022.
 * @File name:
 * @Author: Zuo Yiming(zuoyiming98@buaa.edu.cn)
 * @Version: V1.0
 * @Date: 2022-10-17 10:15:16
 * @Description:B样条实现
 * @Others: None
 * @History: <time>   <author>    <version >   <desc>
 */

#include "include/b_spline.h"

#include <iostream>
#include <vector>

using namespace std;

void BSpline::CalculateKnots(const int &size) {
  int knot_size = size + order_ + 1;
  for (int i = 0; i < order_ + 1; i++) {
    base_nodes_.emplace_back(0.0f);
  }
  int valid_seg = knot_size - 2 * (order_ + 1) + 1;
  for (int i = 1; i < valid_seg; i++) {
    base_nodes_.emplace_back(static_cast<float>(i) /
                             static_cast<float>(valid_seg));
  }
  for (int i = 0; i < order_ + 1; i++) {
    base_nodes_.emplace_back(1.0f);
  }
  cout << "knots: ";
  for (auto i : base_nodes_) {
    cout << i << "  ";
  }
  cout << endl;
}

Pointlist BSpline::GenerateBSplineCurve(const int &order,
                                        const Pointlist &control_pts) {
  order_ = order;
  CalculateKnots(control_pts.size());
}